using System;
using System.Collections.Generic;
using System.Text;
using Pixysoft.Framework.Verifications;
using Pixysoft.Weblications.Sango.Constant;
using Pixysoft.Weblications.Sango.Formular;

namespace Pixysoft.Weblications.Sango.Battle
{
    class SkillSingleFaintSkill : LastingBattleSkill, IBattleSkill
    {
        public SkillSingleFaintSkill()
            : base(SkillTypecodeCollection.SKILL_01_DIZZY)
        {
        }

        public void apply(BattleActionHistory action, IBattleSkillAttack skillattack, Battler attacker, BattleTeam attacks, BattleTeam defenses)
        {
            Battler defenser = defenses.getOneApplier(attacker);

            if (defenser == null)
                return;

            int powerValue = attacker.getPowervalue();
            attacker.clearPowervalue();

            if (!BattleFormular.skillAttackHit(attacker, defenser))
            {
                BattleActionItemHistory actionItem = action.createItem(defenser, BattleActionItemTypecodeCollection.ATTACK_MISS);
                actionItem.Attacker = (attacker.createHistory());
                actionItem.Defenser = (defenser.createHistory());
                return;
            }
            else
            {
                long hpValue = BattleFormular.skillAttackDamage(attacker, defenser, powerValue);
                defenser.reduceHpPointValue(hpValue);
                // defenser.addPowervalue();

                IBattleSkillStatus status = skillattack.createDefaultStatus();
                status.setCanSkillAttack(false);
                status.setCanPhysicalAttack(false);
                skillattack.addAffect(defenser, status);
                attacker.addRunningAttack(skillattack);

                BattleActionItemHistory actionItem = action.createItem(defenser, BattleActionItemTypecodeCollection.ATTACK_SUCCEED);
                actionItem.Attacker = (attacker.createHistory());
                actionItem.Defenser = (defenser.createHistory());
            }
        }


        public int getLastingCount()
        {
            return 1;
        }
    }
}